package com.example.administrator.x3picturetransliteration.Home.Presenter.Activity;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.example.administrator.x3picturetransliteration.Base.BasePresenter;
import com.example.administrator.x3picturetransliteration.Base.HttpGo;
import com.example.administrator.x3picturetransliteration.Bean.BuyingMembersBean;
import com.example.administrator.x3picturetransliteration.Bean.HttpDataBean;

import java.util.HashMap;
import java.util.Map;

import rx.subscriptions.CompositeSubscription;

/**
 * 购买会员
 * Created by Administrator on 2019/9/9.
 */

public class BuyingMembersPresenter extends BasePresenter{

    public BuyingMembersPresenter(Context context, CompositeSubscription mCompositeSubscription) {
        super(context, mCompositeSubscription);
    }

    /** vip购买列表 规格列表 */
    public void list(final Callback mCallback){

        mCompositeSubscription.add(

                mHttpGo.postSubscription("sys_vip_price/list", new HashMap<String, String>(), null,new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0){

                            if (httpDataBean.getData()!=null)mCallback.getData(JSON.parseArray(httpDataBean.getData()+"",BuyingMembersBean.class));
                        }
                    }
                })
        );
    }

    /** 购买会员 */
    public void add(Map<String,String> httpdata, final Callback mCallback){

        mCompositeSubscription.add(

                mHttpGo.postSubscription("user_order/add", httpdata,null, new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0){

                            if (httpDataBean.getData()!=null){

                                Map<String,String> map = (Map<String, String>)httpDataBean.getData();
                                if (map.get("param")!=null)mCallback.getData(map.get("param"));
                            }

                        }
                    }
                })
        );

    }

    /** 获取用户协议 */
    public void Agreement(final Callback mCallback){

        Map<String,String> httpdata = new HashMap<>();

        httpdata.put("id","2");

        mCompositeSubscription.add(

                mHttpGo.postSubscription("sys_protocol/get", httpdata, null,new HttpGo.HttpGoCallback() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpDataBean httpDataBean) {

                        if (httpDataBean.getCode()==0){

                            if (httpDataBean.getData()==null)return;

                            Map<String,String> map = (Map<String,String>)httpDataBean.getData();

                            mCallback.getData(map.get("content"));
                        }
                    }
                })
        );

    }

}
